package com.scap.authen.util;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;

import org.springframework.web.multipart.MultipartFile;

public class UploadFile {

	public boolean uploadFileHandler(MultipartFile voFile,String vnPath) {

	 	String vnName = voFile.getOriginalFilename();
	 
		if (!voFile.isEmpty()) {
			if (voFile.getContentType().indexOf("image")!=(-1)) {
				try {
					
					byte[] bytes = voFile.getBytes();


					File dir = new File(vnPath+ File.separator+"/application");
					if (!dir.exists())
						dir.mkdirs();
					
					// Create the file on server
					File serverFile = new File(dir.getAbsolutePath()
							+ File.separator + vnName);
					BufferedOutputStream stream = new BufferedOutputStream(
							new FileOutputStream(serverFile));
					stream.write(bytes);
					stream.close();

					return true;
				} catch (Exception e) {
					return false;
				}
			}else{
				return false;
			}
			
		} else {
			return false;
		}
	}
}
